package com.noahsloan.groovy.algorithms

/**
 * @author noah
 *
 */
public class Node extends Expando {

	Node(Map props = [:]) {
		super(props)
		this.createEdge = GraphAlgorithms.createEdge		
	}
	
	def connect(node) {
		def edge = createEdge(this,node)
		outgoing << edge
		node.incoming << edge
		edge
	}
	
	boolean equals(o) {
		data?.equals(o.data) 
	}
	
	int hashCode() {
		data?.hashCode()
	}
	
	def remove() {
		outgoing*.remove()
		incoming*.remove()
		this
	}
	
	String toString() {
		"${data}"
	}	
	
}
